<?php
namespace app\merchant\controller\merchant;
use app\common\controller\BaseController;
use app\common\service\merchant\MerchantShopGroupService;
use app\common\validate\merchant\MerchantShopGroupValidate;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("店铺分组")
 * @Apidoc\Group("merchant")
 * @Apidoc\Sort("250")
 */
class MerchantShopGroup extends BaseController
{
    /**
    * @Apidoc\Title("店铺分组列表")
    * @Apidoc\Query(ref="pagingQuery")
    * @Apidoc\Query(ref="sortQuery")
    * @Apidoc\Query(ref="searchQuery")
    * @Apidoc\Query(ref="dateQuery")
    * @Apidoc\Returned(ref="expsReturn")
    * @Apidoc\Returned(ref="pagingReturn")
    * @Apidoc\Returned("list", type="array", desc="店铺分组列表", children={
    *   @Apidoc\Returned(ref="app\common\model\MerchantShopGroupModel", field="id,title,repurchase_days,is_disable,create_time,update_time")
    * })
    */
    public function list()
    {
        $where = $this->where(where_delete());
        $where[] = ['merchant_id','=',mer_id()];
        $data = MerchantShopGroupService::list($where, $this->page(), $this->limit(), $this->order());
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺分组信息")
    * @Apidoc\Query(ref="app\common\model\MerchantShopGroupModel", field="id")
    * @Apidoc\Returned(ref="app\common\model\MerchantShopGroupModel")
    */
    public function info()
    {
        $param = $this->params(['id/d' => '']);
        validate(MerchantShopGroupValidate::class)->scene('info')->check($param);
        $data = MerchantShopGroupService::info($param['id']);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺分组添加")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantShopGroupModel", field="title,repurchase_days,is_disable")
    */
    public function add()
    {
        $param = $this->params(MerchantShopGroupService::$edit_field);
        validate(MerchantShopGroupValidate::class)->scene('add')->check($param);
        $param['merchant_id'] = mer_id();
        $data = MerchantShopGroupService::add($param);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺分组修改")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantShopGroupModel", field="id,title,repurchase_days,is_disable")
    */
    public function edit()
    {
        $param = $this->params(MerchantShopGroupService::$edit_field);
        validate(MerchantShopGroupValidate::class)->scene('edit')->check($param);
        $data = MerchantShopGroupService::edit($param['id'], $param);
        return success($data);
    }
    /**
    * @Apidoc\Title("店铺分组删除")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="idsParam")
    */
    public function dele()
    {
        $param = $this->params(['ids/a' => []]);
        validate(MerchantShopGroupValidate::class)->scene('dele')->check($param);
        $data = MerchantShopGroupService::dele($param['ids']);
        return success($data);
    }
    /**
     * @Apidoc\Title("店铺分组禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantShopGroupModel", field="is_disable")
     */
    public function disable()
    {
        $param = $this->params(['ids/a' => [], 'is_disable/d' => 0]);
        validate(MerchantShopGroupValidate::class)->scene('disable')->check($param);
        $data = MerchantShopGroupService::edit($param['ids'], $param);
        return success($data);
    }
    /**
     * @Apidoc\Title("选择店铺分组")
     * @Apidoc\Query(ref="sortQuery")
     * @Apidoc\Query(ref="searchQuery")
     * @Apidoc\Query(ref="dateQuery")
     * @Apidoc\Returned(ref="app\common\model\SettingStoreFlagModel", field="id,title")
     */
    public function select()
    {
        $where = $this->where(where_delete());
        $where[] = ['merchant_id','=',mer_id()];
        $data = MerchantShopGroupService::list($where,0,0, $this->order(),'id as value,title as label,is_disable as disable');
        return success($data);
    }
}
